package com.hunt.controller;

import com.hunt.model.entity.IndexNewsDetail;
import com.hunt.model.entity.IndexNewsInfo;
import com.hunt.service.IndexNewsService;
import com.hunt.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @Author sjs
 * @Date 2020/11/13
 * @Description
 */
@Api(value = "手机app端,大盘模块")
@Controller
@RequestMapping(path = "/app/indexnews")
public class IndexNewsController extends BaseController {

    @Autowired
    @Resource
    private IndexNewsService indexNewsService;
    @ApiOperation(value = "大盘列表查询", httpMethod = "GET", produces = "application/json", response = Result.class)
    @ResponseBody
    @RequestMapping(value = "getIndexNewsInfo", method = RequestMethod.GET)
    public Result findIndexNewsInfo(@RequestParam(value = "time",required = false) String time,
                                @RequestParam(value = "sizeUP", defaultValue = "10") Integer sizeUP) {
        List<IndexNewsInfo> IndexNewsInfo=null;
        if(time==null||"null".equals(time)){
            Date da=new Date();
            long datimestamp=da.getTime();
            IndexNewsInfo = indexNewsService.findIndexNewsByPage(datimestamp, sizeUP);
        }
        else {
             IndexNewsInfo = indexNewsService.findIndexNewsByPage(Long.valueOf(time),sizeUP);
        }
        return Result.success(IndexNewsInfo);
    }

    @ApiOperation(value = "大盘列表详情查询", httpMethod = "GET", produces = "application/json", response = Result.class)
    @ResponseBody
    @RequestMapping(value = "getIndexNewsDetail", method = RequestMethod.GET)
    public Result getIndexNewsDetail(@RequestParam(value = "timestamp") Long stamp) {
        IndexNewsDetail detail =  indexNewsService.findIndexNewsDetailBystamp(stamp);
        return Result.success(detail);
    }
    @ApiOperation(value = "大盘列表详情界面", httpMethod = "GET",produces = "text/html")
    @RequestMapping(value = "getIndexNewsDetailPage", method = RequestMethod.GET)
    public  String getIndexNewsDetailPC(@RequestParam(value = "timestamp") Long stamp, Model model) {
         IndexNewsDetail detail =  indexNewsService.findIndexNewsDetailBystamp(stamp);
         model.addAttribute("detail",detail);
        return "pc/oldpage";
    }
    @ApiOperation(value = "大盘列表详情界面新", httpMethod = "GET",produces = "text/html")
    @RequestMapping(value = "getIndexNewsDetailNewPage", method = RequestMethod.GET)
    public  String getIndexNewsDetailOldPage(@RequestParam(value = "timestamp") Long stamp, Model model) {
        IndexNewsDetail detail =  indexNewsService.findIndexNewsDetailBystamp(stamp);
        model.addAttribute("detail",detail);
        return "pc/newpage";
    }
}